package top.as.sean.api.controller.system;

import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import top.as.sean.biz.system.IMenu;
import top.as.sean.common.response.Result;
import top.as.sean.dao.dto.system.MenuAdd;
import top.as.sean.dao.dto.system.MenuEdit;
import top.as.sean.dao.dto.system.MenuSearch;
import top.as.sean.dao.vo.system.MenuTree;

import java.util.List;

/**
 * 菜单管理
 *
 * @author: ArchieSean
 * @create: 2023/1/2
 */
@RestController
@RequestMapping("menu")
@RequiredArgsConstructor
public class MenuController {
    /**
     * menu
     */
    private final IMenu iMenu;

    /**
     * 新增菜单
     *
     * @param dto 入参
     * @return boolean
     */
    @PostMapping("add")
    public Result<Boolean> addMenu(@Validated @RequestBody MenuAdd dto) {
        return Result.success(iMenu.addMenu(dto));
    }

    /**
     * 查询树形菜单数据
     *
     * @param dto 入参
     * @return list
     */
    @GetMapping("tree")
    public Result<List<MenuTree>> queryMenuTree(@ModelAttribute MenuSearch dto) {
        return Result.success(iMenu.queryMenuTree(dto));
    }

    /**
     * 编辑部门
     *
     * @param dto 入参
     * @return boolean
     */
    @PutMapping("edit")
    public Result<Boolean> editMenu(@Validated @RequestBody MenuEdit dto) {
        return Result.success(iMenu.editMenu(dto));
    }

    /**
     * 删除菜单
     *
     * @param id id
     * @return boolean
     */
    @DeleteMapping("delete")
    public Result<Boolean> deleteMenu(@RequestParam("id") Long id) {
        return Result.success(iMenu.deleteMenu(id));
    }
}
